<%@ page language="java" contentType="text/html; UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   <%
		String base = request.getContextPath();
		request.setAttribute("base", base);
	%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${base}/resources/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
	function change1(oneSelf){
		$("input[name=tr1]").each(function(){
			$(this).attr('checked',oneSelf.checked);
		})
	}
	function submit(){
		var arr=new Array();
		var i=0;
		$("input[name=tr1]:checked").each(function(){
			arr[i]=$(this).val();
			i++;
		})
		if(arr.length>0){
			$.ajax({
				url:"${base}/purchaseCommodity",
				data:{"arr":arr},
				type:'post',
				success:function(data){
				    if(data=="success"){
				    	alert("购买成功");
				    	location.href="${base}/CommodityController/show";
				    }
				}		
			})
		}else{
			alert("请最少选择1条");
		}
	}
</script>
</head>
<body>
	<div>
		<table>
			<c:forEach var="shop" items="${shopList}">
				<tr>
					<td><input type="checkbox" name="tr1" value="${shop.cartid}"/></td>
					<td><img src="${base}/resources/images/none.jpg"/></td>
					<td><label>${shop.commodity.commodityname}</label><br/><label>${shop.countprice}</label> </td>
				</tr>
			</c:forEach>
			<tr>
				<td align="left"><input type="checkbox" onclick="change1(this)"/></td>
				<td align="right"><input type="button" value="结算" onclick="submit()"></td>
			</tr>
		</table>
	</div>
</body>
</html>